package com.baizhi.wwk.controller;

import com.baizhi.wwk.dto.Dto;
import com.baizhi.wwk.entity.Category;
import com.baizhi.wwk.service.CategoryService;
import com.baizhi.wwk.service.CategoryServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@CrossOrigin
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryServiceImpl categoryService;

    @RequestMapping("queryOnePage")
    @ResponseBody//一级分页
    public Map<String,Object> queryOnePage(@RequestBody Dto dto){
        return categoryService.queryOnePage(dto.getPage(),dto.getPageSize());
    }
    @RequestMapping("add")
    @ResponseBody
    public void add(@RequestBody Category category){
        categoryService.addFirst(category);

    }
    @RequestMapping("delete")
    @ResponseBody
    public Map<String, Object> delete(@RequestBody Dto dto){
        return categoryService.delete(dto.getId());
    }

    @RequestMapping("queryTwoPage")
    @ResponseBody//二级分页
    public Map<String,Object> queryTwoPage(@RequestBody Dto dto){
        return categoryService.queryTwoPage(dto.getPage(), dto.getPageSize(), dto.getCategoryId());
    }
    @RequestMapping("queryByLevelsCategory")
    @ResponseBody
    public List<Category> queryByLevelsCategory(){
        return categoryService.queryByLevelsCategory();
    }
    @RequestMapping("queryById")
    @ResponseBody
    public Category queryById(int id){
        return categoryService.queryById(id);
    }
    @RequestMapping("update")
    @ResponseBody
    public void update(@RequestBody Category category){
        categoryService.update(category);
    }
}
